//
//  XHRMedicalRecordTopView.m
//  快医
//
//  Created by 胥鸿儒 on 16/7/6.
//
//

#import "XHRMedicalRecordTopView.h"
#import "XHRMedicalMessageButton.h"
#define XHRMedicalLabelFont [UIFont systemFontOfSize:18]
@interface XHRMedicalRecordTopView()

/**头像视图*/
@property(nonatomic,weak)UIImageView *iconView;

/**分割线*/
@property(nonatomic,weak)UIView *separateView;

/**姓名标签*/
@property(nonatomic,weak)UILabel *nameLabel;
/**性别*/
@property(nonatomic,weak)XHRMedicalMessageButton *genderButton;
/**年龄标签*/
@property(nonatomic,weak)UILabel *ageLabel;

/**idCard*/
@property(nonatomic,weak)XHRMedicalMessageButton *idCardButton;
/**phoneNumber*/
@property(nonatomic,weak)XHRMedicalMessageButton *phoneNumberButton;
/**地区*/
@property(nonatomic,weak)XHRMedicalMessageButton *localButton;
@end
@implementation XHRMedicalRecordTopView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {

    }
    return self;
}
#pragma mark -
#pragma mark - layoutSubviews
- (void)layoutSubviews
{
    [super layoutSubviews];

    [self.iconView makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.offset(20);
        make.width.height.equalTo(100);
    }];
    
    
}

#pragma mark -
#pragma mark - 懒加载topView
- (UIImageView *)iconView
{
    if (!_iconView) {
        //初始化视图
        UIImageView *iconView = [[UIImageView alloc]init];
        [self addSubview:iconView];
        iconView.image = [UIImage imageNamed:@"good_image_default"];
        _iconView = iconView;
        
        [self.separateView makeConstraints:^(MASConstraintMaker *make) {
            make.leading.offset(10);
            make.trailing.offset(-10);
            make.height.equalTo(1);
            make.bottom.offset(0);
        }];
        
        [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconView.bottom).offset(10);
            make.trailing.leading.equalTo(self.iconView);
            make.bottom.offset(-10);
        }];
        
        [self.genderButton makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconView);
            make.leading.equalTo(self.iconView.trailing).offset(15);
            make.width.greaterThanOrEqualTo(40);
        }];
        [self.ageLabel makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.genderButton);
            make.leading.equalTo(self.genderButton.trailing).offset(40);
        }];
        [self.idCardButton makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.genderButton);
            make.top.equalTo(self.genderButton.bottom).offset(15);
            make.trailing.offset(0);
        }];
        [self.phoneNumberButton makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.genderButton);
            make.top.equalTo(self.idCardButton.bottom).offset(15);
            make.trailing.offset(0);
        }];
        [self.localButton makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.genderButton);
            make.top.equalTo(self.phoneNumberButton.bottom).offset(15);
            make.trailing.offset(0);
        }];
    }
    return _iconView;
}
- (UIView *)separateView
{
    if (!_separateView) {
        //设置分割线
        UIView *separateView = [[UIView alloc]init];
        separateView.backgroundColor = XHRColorWithRGB(140, 140, 140);
        [self addSubview:separateView];
        _separateView = separateView;
    }
    return _separateView;
}
- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.font = XHRMedicalLabelFont;
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"王二狗";
        [self addSubview:label];
        _nameLabel = label;
    }
    return _nameLabel;
}
- (XHRMedicalMessageButton *)genderButton
{
    if (!_genderButton) {
        XHRMedicalMessageButton *genderButton = [[XHRMedicalMessageButton alloc]init];
        [genderButton setImage:[UIImage imageNamed:@"0"] forState:UIControlStateNormal];
        [genderButton setTitle:@"男" forState:UIControlStateNormal];
        [self addSubview:genderButton];
        _genderButton = genderButton;
    }
    return _genderButton;
}
- (UILabel *)ageLabel
{
    if (!_ageLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.font = XHRMedicalLabelFont;
        label.text = @"18";
        [self addSubview:label];
        _ageLabel = label;
    }
    return _ageLabel;
}
- (XHRMedicalMessageButton *)idCardButton
{
    if (!_idCardButton) {
        XHRMedicalMessageButton *button = [[XHRMedicalMessageButton alloc]init];
        [button setImage:[UIImage imageNamed:@"idCard"] forState:UIControlStateNormal];
        [button setTitle:@"2342342342342" forState:UIControlStateNormal];
        [button sizeToFit];
        [self addSubview:button];
        _idCardButton = button;
    }
    return _idCardButton;
}
- (XHRMedicalMessageButton *)phoneNumberButton
{
    if (!_phoneNumberButton) {
        XHRMedicalMessageButton *button = [[XHRMedicalMessageButton alloc]init];
        [button setImage:[UIImage imageNamed:@"phone"] forState:UIControlStateNormal];
        [button setTitle:@"13157132432" forState:UIControlStateNormal];
        [self addSubview:button];
        _phoneNumberButton = button;
    }
    return _phoneNumberButton;
}
- (XHRMedicalMessageButton *)localButton
{
    if (!_localButton) {
        XHRMedicalMessageButton *button = [[XHRMedicalMessageButton alloc]init];
        [button setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateNormal];
        [button setTitle:@"上海市" forState:UIControlStateNormal];
        [self addSubview:button];
        _localButton = button;
    }
    return _localButton;
}
@end
